/* Project: POPS
 * CS 279, Vanderbilt University
 * by: Igor I. Ges, Michael S. Parrish, Mark E. Sakauye
 *
 *  This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.popsDB.java.example;

import java.math.*;
import java.util.Date;
import java.util.Collection;
import com.popsDB.java.dao.CustomersDao;
import com.popsDB.java.dto.Customers;
import com.popsDB.java.exceptions.CustomersDaoException;
import com.popsDB.java.factory.CustomersDaoFactory;

public class CustomersTests
{
	public static void main(String[] arg) throws Exception
	{
		// Uncomment one of the lines below to test the generated code

		findAll();
		findWhereCustomerIDEquals(3);
		findWhereBillingIDEquals(2);
		findWherePriceSheetEquals(1);
		findWherePriceSheetTemplateEquals(1);
		short tmp = 1;
		findWhereIsActiveEquals(tmp);
		findWhereHistoryIntervalEquals(30);
	}

	// Finds all customers in the database and checks their names.
	public static void findAll()
	{
		String test = null;
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findAll();
			System.out.println("\n ****** Test Find All Customers ******");
			String _test[] = new String[4];
			_test[0] = "CustomerOne";
			_test[1] = "CustomerTwo";
			_test[2] = "CustomerThree";
			_test[3] = "CustomerFour_One";
			if (_result.length != _test.length) {
				System.out.println("fail in if");
				test = "FAILED\n";
			}
			else {
				int count = 0;
				for (int i=0; i<_result.length; i++ ) {
					//display( _result[i] );
					if (!_result[i].getCustomerName().toString().equals(_test[i].toString())) {
						System.out.println("fail in for");
						count = count + 1;
					}
				}
				if (count == 0) {
					test = "PASSED\n";
				}
				else {
					test = "FAILED\n";
				}
			}
		}
		catch (Exception _e) {
			_e.printStackTrace();
		}
		System.out.println(test);


	}

	// Finds where customer ID = customerID 
	public static void findWhereCustomerIDEquals(int customerID)
	{
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findWhereCustomerIDEquals(customerID);
			System.out.println("\n ****** Test Where Customer ID = " + customerID + " ******");
			int count = 0;
			for (int i = 0; i < _result.length; i++) {
				if (_result[0].getCustomerID() != customerID) {
					count = count + 1;
				}
			}
			if (count == 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}
		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	// Finds where billing ID = billingID
	public static void findWhereBillingIDEquals(int billingID)
	{
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findWhereBillingIDEquals(2);
			System.out.println("\n ****** Test Find Where Billing ID = " + billingID  
					+ "******");
			int count = 0;
			for (int i = 0; i < _result.length; i++) {
				if (_result[0].getBillingID() == billingID) {
					count = count + 1;
				}
			}
			if (count != 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}

		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	// Finds where price sheet = priceSheet
	public static void findWherePriceSheetEquals(int priceSheet)
	{
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findWherePriceSheetEquals(priceSheet);
			System.out.println("***** Test Find Where Price Sheet = " + priceSheet
					+ " *****");
			int count = 0;
			for (int i=0; i<_result.length; i++ ) {
				if (_result[i].getPriceSheet() != priceSheet) {
					count = count + 1;
				}
			}
			if (count == 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}

		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	// Finds where price sheet template = priceSheetTemplate
	public static void findWherePriceSheetTemplateEquals(int priceSheetTemplate)
	{
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findWherePriceSheetTemplateEquals(priceSheetTemplate);
			System.out.println("***** Test Find Where Price Sheet Template = " 
					+ priceSheetTemplate + " *****");
			int count = 0;
			for (int i=0; i<_result.length; i++ ) {
				if (_result[i].getPriceSheetTemplate() != priceSheetTemplate) {
					count = count + 1;
				}
			}

			if (count == 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}
		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	// Finds active/inactive customers
	public static void findWhereIsActiveEquals(short isActive)
	{
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findWhereIsActiveEquals(isActive);
			System.out.println("***** Test Find Where is Active = " + isActive 
					+ " *****");
			int count = 0;
			for (int i=0; i<_result.length; i++ ) {
				if (_result[i].getIsActive() != isActive) {
					count = count + 1;
				}
			}
			if (count == 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}
		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	// Finds where history interval = historyInterval
	public static void findWhereHistoryIntervalEquals(int historyInterval)
	{
		try {
			CustomersDao _dao = getCustomersDao();
			Customers _result[] = _dao.findWhereHistoryIntervalEquals(historyInterval);
			System.out.println("***** Test Find Where History Interval = " + historyInterval
					+ " *****");
			int count = 0;
			for (int i=0; i<_result.length; i++ ) {
				if (_result[i].getHistoryInterval() != historyInterval) {
					count = count + 1;
				}
			}
			if (count == 0) {
				System.out.println("PASSED\n");
			}
			else {
				System.out.println("FAILED\n");
			}			

		}
		catch (Exception _e) {
			_e.printStackTrace();
		}

	}

	public static CustomersDao getCustomersDao()
	{
		return CustomersDaoFactory.create();
	}
}
